package cn.tedu.lianxi1;

public class Text1 {
    public static void main(String[] args) {
        Maipiao a=new Maipiao();
        Thread t1=new Thread(a,"窗口1");
        Thread t2=new Thread(a,"窗口2");
        Thread t3=new Thread(a,"窗口3");
        Thread t4=new Thread(a,"窗口4");
        t1.start();
        t2.start();
        t3.start();
        t4.start();

    }
}
class Maipiao implements Runnable {
    int tickets=100;
    @Override
    public void run() {

        while (true){
            synchronized (this) {
                if (tickets > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "====" + tickets--);

                } else {
                    break;
                }
            }
        }
    }
}